<?php
//$picpath = substr($_GET[pic],0,8);
$filename = $_GET[pic];
$jpg = getimagesize($filename);
//echo $jpg['0'];
if($jpg[0]<=1){
	$filename = 'http://127.0.0.1/westock/images/nopic.gif';
	$jpg = getimagesize($filename);
	}
	
	list($width, $height) = getimagesize($filename);
//print_r($jpg);
$new_width = 100;
$new_height = 100;

// 新尺寸

$image_p = @imagecreatetruecolor($new_width, $new_height);
$b_c = imagecolorallocate($image_p, 255, 255, 255);
imagefill($image_p, 0, 0, $b_c);
//白底
if($width > $height){
	$percent = $height / $new_width;
	$f_w = $width/$percent;
	$f_h = $height/$percent;
	$x = ($f_w-$f_h)/2;
	$y = 0;
	}elseif($width < $height){
		$percent = $width / $new_width;
		$f_w = $width/$percent;
		$f_h = $height/$percent;
		$x = 0;
 		$y = ($f_h-$f_w)/2;
		}elseif($width == $height){
			$f_w = $new_width;
			$f_h = $new_height;
			$x = 0;
			$y = 0;
			}
			//尺寸和位置
//$f_w = $width*($new_width/$width);
//$f_h = $height*($new_width/$width);

	switch ($jpg['mime']) { 
    case "image/gif": 
        $image = imagecreatefromgif($filename);
        break; 
    case "image/jpeg": 
        $image = imagecreatefromjpeg($filename);
        break; 
    case "image/png": 
        $image = imagecreatefrompng($filename);
        break; 
    case "image/bmp": 
        $image = imagecreatefromwbmp($filename);
        break; 
} 
imagecopyresampled($image_p, $image, -$x, -$y, 0, 0, $f_w, $f_h, $width, $height);
ImageJPEG($image_p , null, 100); 
?> 